package com.hebeu.gfh.controller;

import com.hebeu.gfh.pojo.po.ClubFollow;
import com.hebeu.gfh.pojo.po.Clubs;
import com.hebeu.gfh.service.clubFollowService;
import com.hebeu.gfh.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 刘剑利
 * @Version: v1.0
 */
@RestController
@RequestMapping("/clubFollow")
public class clubFollowController {

    @Autowired
    clubFollowService clubFollowService;

    //根据userid查询所关注社团的数量
    @PostMapping("/findClubNumByuserId")
    public R findClubNumByuserId(int userId){
       int num= clubFollowService.findClubNumByuserId(userId);
       return R.ok(num);
    }
    //根据userid查询所关注的社团
    @PostMapping("/findClubByuserId")
    public R findClubByuserId(int userId){
        List<Clubs> clubsList = clubFollowService.findClubByuserId(userId);
        return R.ok(clubsList);
    }

    //通过userid和clubId查询是否关注此社团
    @PostMapping("/findFollowByuserIdAndClubId")
    public R findFollowByuserIdAndClubId(ClubFollow clubFollow){
        int follow =clubFollowService.findFollowByuserIdAndClubId(clubFollow);
        return R.ok(follow);
    }

    //添加关注
    @PostMapping("/addFollow")
    public R addFollow(ClubFollow clubFollow){
        try {
                clubFollowService.addFollow(clubFollow);
        }catch (Exception e){
            System.out.println("异常为"+e);
            System.out.println("-------------------------");
            return R.error(500,"添加失败");
        }
        return  R.ok("添加成功");
    }

    //取消关注
    @PostMapping("/deleteFollow")
    public R deleteFollow(ClubFollow clubFollow){
        try {
            clubFollowService.deleteFollow(clubFollow);
        }catch (Exception e){
            System.out.println("异常为"+e);
            System.out.println("-------------------------");
            return R.error(500,"取消关注失败");
        }
        return  R.ok("取消关注成功");
    }
}
